package org.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping("/nacos-config")
@RefreshScope
public class NacosConfigController {
	@Autowired
	private ApplicationContext applicationContext;
	
	//1 硬编码方式
	@GetMapping("/test1")
	public String nacosConfingTest1() {
		
		Environment env = applicationContext.getEnvironment();
		return env.getProperty("config.appName");
	}
 
//	@Value("${config.appName}")
	private String appName;
	//2 注解方式
	@GetMapping("/test2")
	public String nacosConfingTest2() {
		return appName;
	}
 
 
 
}